﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using HR60_PanelSoft.View.Base;
using HR60_PanelSoft.View.TabForms.ListItems;
using HR60_PanelSoft.Model;
using HR60_PanelSoft.Model.BaseModel;

namespace HR60_PanelSoft.View.TabForms
{
	public partial class PanelForm_ExPage : BaseForm
	{
        //GC: 修改PanelForm_ExPage @s3
        /* s1 */
        Model.Panel _cur_panel = new Model.Panel();
        /* end of s1 */


		public PanelForm_ExPage()
		{
			InitializeComponent();
		}

		// 绑定数据
		public override void refreshFormData(System.Collections.Generic.IDictionary<string, object> dataMap)
		{
            /* s2: 将关联的panel，提升至私有变量 */
            _cur_panel = null;
			_cur_panel = (HR60_PanelSoft.Model.Panel) dataMap["panel"];

            /* 这里的原则是：一个工程只有一个同类型的高级设备 */

            /* end of s2 */

			// 遍历特殊设备
			panelMain.Controls.Clear();
			foreach (DeviceGroup group in deviceGroups)
			{
				foreach (Device device in group.devices)
				{
					if (device.type.exType != ExDeviceType.NULL)
					{
						// 显示分机列表
						SubExDeviceSelect ss = new SubExDeviceSelect();
						ss.bindExDevice(device);
						panelMain.Controls.Add(ss);

						// 初始化选项
						switch(device.type.exType)
						{
							case ExDeviceType.CentralAircon:
                                ss.Value = _cur_panel.airconPage.mappingSubExDevice;
								break;
							case ExDeviceType.CentralHeating:
                                ss.Value = _cur_panel.heatingPage.mappingSubExDevice;
								break;
							case ExDeviceType.CentralNewWind:
                                ss.Value = _cur_panel.newWindPage.mappingSubExDevice;
								break;
							case ExDeviceType.BGM:
                                ss.Value = _cur_panel.bgmPage.mappingSubExDevice; /* 目前仍不能保存 */
								break;
						}
					}
				}
			}
		}

		// 数据修改事件
		public override void onFormChanged(BaseFormControl sender, System.EventArgs e)
		{
            /*s3: 将SubExDeviceSelect状态更改保存到内存*/


            if (!(sender is SubExDeviceSelect))
                return;
            /* 1. 检索状态修改所属的父设备 */
            SubExDeviceSelect seds = (SubExDeviceSelect)sender;
            Device d = (Device)seds.Tag;
            
            /* 2. 将子设备列表的最新状态进行保存 */
            if (d.type.exType == ExDeviceType.NULL)
                return;
            switch (d.type.exType)
            {
                case ExDeviceType.CentralAircon:
                    _cur_panel.airconPage.mappingSubExDevice = (List<string>)seds.Value;
                    break;
                case ExDeviceType.CentralHeating:
                    _cur_panel.heatingPage.mappingSubExDevice = (List<string>)seds.Value;
                    break;
                case ExDeviceType.CentralNewWind:
                    _cur_panel.newWindPage.mappingSubExDevice = (List<string>)seds.Value;
                    break;
                case ExDeviceType.BGM:
                    _cur_panel.bgmPage.mappingSubExDevice = (List<string>)seds.Value;
                    break;
                default:
                    break;
            }

            /* end of s3 */
		}
	}
}
